<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
    <link rel="stylesheet" href="/${BasePath}/static/mobile/css/ydui.css" />
    <link rel="stylesheet" href="/${BasePath}/static/mobile/css/base.css" />
    <link rel="stylesheet" href="/${BasePath}/static/mobile/css/style.css" />
    <link rel="stylesheet" href="/${BasePath}/static/mobile/css/swiper.min.css" />  
    <title>半岛云</title>  
</head>
<body>
<input type="hidden" id="active" value="grzx">
<input type="hidden" id="orderId" value="">
	<div class="wrap">
		<!--tab-->
		<ul class="orderstab">
		   <li><a href="/${BasePath}/order/allOrder">全部</a></li>
		   <li class="active"><a href="/${BasePath}/order/pendingPayOrder">待付款</a></li>		
		   <li><a href="/${BasePath}/order/toBeShippedOrder">待发货</a></li>	
		   <li><a href="/${BasePath}/order/toBeReceivedOrder">待收货</a></li>	
		   <li><a href="/${BasePath}/order/completedOrder">已完成</a></li>	
		</ul>
		
		<div class="container_inner marginbottom55" id="J_List">
		<!--list-->
		<ul class="orders_list" id="J_ListContent">
		
		</ul>
		</div>
		
		<!--导航栏-->
        <#include "/common/foot.html">
	</div>
		<div class="m-actionsheet" id="actionSheet">
		    <a href="javascript:;" class="actionsheet-item zfb">支付宝支付</a>
		    <a href="javascript:;" class="actionsheet-item wx">微信支付</a>
		    <a href="javascript:;" class="actionsheet-item wxzz">已微信转账</a>
		    <a href="javascript:;" class="actionsheet-action" id="cancel">取消</a>
		</div> 
</body>

<script type="text/javascript" src="/${BasePath}/static/mobile/js/ydui.flexible.js"></script>
<script type="text/javascript" src="/${BasePath}/static/mobile/js/ydui.js"></script>
<script type="text/javascript">
    $(function(){
    	//eruda.init();
    	$("ul.orderstab").on("click","li",function(){
    		$(this).addClass("active").siblings().removeClass("active")
    	})
    	
	})
</script>
<script>
function temp(id){
	$("#orderId").val(id);
}
    /* 通过自定义的方法获取数据【通常是需要定义变量当前第几页page，和每页请求的记录数pageSize】 */
    var page = 1, pageSize = 2, shopid = 11;

    $('#J_List').infiniteScroll({
        pageSize: pageSize,
        initLoad: true,
        loadingHtml: '<img src="http://static.ydcss.com/uploads/ydui/loading/loading10.svg"/>', /* 当然也可以<img src="../img/loading.gif" /> */
        loadListFn: function () {
            var def = $.Deferred();

            /* 通过自定义的方法获取数据 */
            $.ajax({
                url: '/${BasePath}/order/queryOrderPage',
                dataType: 'json',
                data: { page: page, limit: pageSize,orderStatus: ${orderStatus!''}},
                success: function (ret) {
                	if(ret.code!=1){
                		if(ret.count===ret.page){
                    		var temp = new Array();
                    		temp.push("暂无数据")
                    		def.resolve(temp);
                		}
                        /* 假设ret.list为后端返回的列表数组 */
                        var html ="";
                        var list = ret.data;
                    	var clas="dfk";
                    	var liex="待付款"
                    	var target="'#actionSheet'"
                    	var closeElement="'#cancel'"
                        for (var i=0;i<list.length;i++){
    						if(list[i].orderStatus==="2"){
    							clas="dfh"
    							liex="待发货"
    						}
    						if(list[i].orderStatus==="3"){
    							clas="dsh"
    							liex="待收货"
    						}
    						if(list[i].orderStatus==="4"){
    							clas="ywc"
    							liex="已完成"
    						}
                        	html =html+'<li class="'+clas+'">'
                        		        +'<dl>'
                        		        +'<img src="/${BasePath}/static/mobile/img/ywc.png" />'
                        		        	+'<dt>'
                        		        		+'<h2>订单号:'+list[i].orderNum+'</h2>'
                        		        		+'<span>'+liex+'</span>'
                        		        		+'<i class="icons del">&#xe649;</i>'
                        		        	+'</dt>'
                        		        	+'<dd>'
                        	 var cart = list[i].listShopCartExtend;
                        	 for (var j=0;j<cart.length;j++){
                        		 html =html+'<a href="/${BasePath}/free/productDetial?id='+cart[j].productId+'"><div class="ddinfo">'
    	                    		 			+'<img src="'+cart[j].productCover+'" />'
    	                    		 			+'<p class="productName">'+cart[j].productName+'</p>'
                        		 		    +'</div></a>' 		   
                        	 }
                        	 if(list[i].orderStatus==="1"){
                            	 html =html+'<div class="dd_subinfo">'
    		     		 		    +'<span>共'+cart.length+'件商品</span><span></span>'	
    		   		 		        +'</div>'
    		   		 		        +'<div class="shdz">'
    		   		 		        +'<h4><span>'+list[i].shopAddress.name+'</span><span>'+list[i].shopAddress.phone+'</span></h4>'	
    		   		 		        +'<p>'+list[i].shopAddress.provance+list[i].shopAddress.city+list[i].shopAddress.area+list[i].shopAddress.address+'</p>'    
    		   		 	            +'</div>' 
                        	 }else{
                            	 html =html+'<div class="dd_subinfo">'
    		     		 		    +'<span>共'+cart.length+'件商品</span><span>实付款:<font>￥152</font></span>'	
    		   		 		        +'</div>'
    		   		 		        +'<div class="shdz">'
    		   		 		        +'<h4><span>'+list[i].shopAddress.name+'</span><span>'+list[i].shopAddress.phone+'</span></h4>'	
    		   		 		        +'<p>'+list[i].shopAddress.provance+list[i].shopAddress.city+list[i].shopAddress.area+list[i].shopAddress.address+'</p>'    
    		   		 	            +'</div>'                     		 
                        	 }

    				   		 	            
    				   		 html =html+'<div class="dd_btns">'
    										+'<a class="jh" href="javascript:;">查看物流</a>'
    										+'<a class="qxdd" href="javascript:;" onclick="removeOrder('+list[i].id+')">取消订单</a>'	
    										+'<a class="sqtk" href="javascript:;">申请退款</a>'	
    										+'<a class="zcgm" href="javascript:;">再次购买</a>'	
    										+'<a class="qrsh" href="javascript:;"onclick="confirmOrder('+list[i].id+')">确认收货</a>'	
    										+'<a class="ljzf" href="javascript:;" onclick="temp('+list[i].id+')" data-id="'+list[i].id+'" data-ydui-actionsheet="{target:'+target+',closeElement:'+closeElement+'}">立即支付</a>'	
    									+'</div>' 
    								+"</dd>"
    								+'</dl>'
    								+'</li>'
                        }
                        /* 用你喜欢的方法将获取到的数据拼接成HTML，然后插入；*/
                        /* 建议使用模板引擎，示例使用artTemplate；https://github.com/aui/artTemplate */
                        $('#J_ListContent').append(html);

                        /* 获取数据，并插入页面后，调用resole，并传入当前获取的记录列表集合 */
                        def.resolve(list);

                        /* 页码自增1 */
                        ++page;                		
                	}else{
                		var temp = new Array();
                		temp.push("暂无数据")
                		def.resolve(temp);
                	}

                }
            });

            return def.promise();
        }
    }); 
   
    //支付宝
    $(".zfb").click(function(){
    	YDUI.dialog.confirm('提示',  '前去付款！',  function () {
            var orderId=$("#orderId").val();
		    var form = $("<form>");
 		    form.attr("style","display:none");
 		    form.attr("target","");
 		    form.attr("method","post");
 		    //请求地址
 		    form.attr("action","/${BasePath}/order/orderSettlement");
 		    var input2 = $("<input>");
 		    input2.attr("type","hidden");
 		    input2.attr("name","orderId");
 		    input2.attr("value",orderId);
 		    $("body").append(form);
 		    form.append(input2);
 		    form.submit();
 		    form.remove();   
    	});
    })
/**
 * 取消订单
 * @param id
 */
function removeOrder(id){
    $.ajax({
        url: '/${BasePath}/order/editOrder',
        dataType: 'json',
        data: { "id": id, "orderStatus": "0"},
        success: function (data) {
        	if(data.code==="1"){
        		YDUI.dialog.alert(data.msg, function(){
        			 location.reload();
        	    });
        	}else{
        		YDUI.dialog.alert(data.msg);
        	}
        	
        }
    });
	
}
    
/**
 * 确认收货
 * @param id
 */
function confirmOrder(id){
    $.ajax({
        url: '/${BasePath}/order/editOrder',
        dataType: 'json',
        data: { "id": id, "orderStatus": "4"},
        success: function (data) {
        	if(data.code==="1"){
        		YDUI.dialog.alert(data.msg, function(){
        			 location.reload();
        	    });
        	}else{
        		YDUI.dialog.alert(data.msg);
        	}
        	
        }
    });
	
}
</script>
</html>